import groovy.text.GStringTemplateEngine
import org.springframework.mock.web.MockHttpServletRequest

def template = '''\
<%
def mock_request = new org.springframework.mock.web.MockHttpServletRequest();
%>

<% for( i in 1..10) { %>\
hello $i - ${i * i}
${}
<%}%>\

<%
map.put('a', 'first');
map.put('b', 'second');
%>\

$map

'''

def engine = new GStringTemplateEngine()
def binding = ["firstname":"Sam", "lastname":"Pullara", "city":"San Francisco", "month":"December", "signed":"Groovy-Dev", "map":new HashMap()]
result = engine.createTemplate(template).make(binding)

// the template only parsed when toString() method called
a = result.toString()

print binding.map

